<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请求封装</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css">
</head>
<body>
    

<script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- <script src="dish/request.min.js"></script> -->
<script src="dish/request.js"></script>
<script>
    function url(api){
        //let url = 'https://api.baidu.com/index.php?',
        let url = 'http://t.weikuw.com/index.php?',
            uri = api.split('/');
        console.log('uri:', uri);
        if (uri.length == 1) {
            url = url + 'g=Wecha&m=Forum&a=' + api;
        } else if (uri.length == 2) {
            url += 'g=Wecha&m=' + uri[0] + '&a=' + uri[1];
        } else {
            url += 'g=' + uri[0] + '&m=' + uri[1] + '&a=' + uri[2];
        }
        return url;
    }

    var $ = new Request({
        // url: 'https://api.baidu.com/api/',
        url: url,
        methods: {
            fn1(){ console.log('fn1 执行')},
            fn2(){ console.log('fn2 执行')}
        },
        headers: {
            token: '32a5twVQRJFKml85h',
        },
        loading(){
            var vm = new Vue();
            return vm.$toast({
                type: 'loading',
                message: '正在加载...',
                duration: 0,
                forbidClick: true
            });
        },
        hideLoading($load){
            $load.clear();
        },
        alert(msg){
            console.log('msg:', msg);
            new Vue().$dialog.alert({
				title: '温馨提示',
				message: msg,
				confirmButtonText: '好的',
				confirmButtonColor: '#409EFF'
			});
        }
    });
    
    // { user: 'yyh'},
    $.get('Forum/get_list').then(res => {
        console.log('login:', res);
    })
</script>
</body>
</html>